package com.vision.core.cm.db.data;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.sf.gilead.pojo.gwt.LightEntity;

@Entity
@Table(name = CompanyGroup.TABLE)
public class CompanyGroup extends LightEntity implements Serializable{

	private static final long serialVersionUID = 7563821243682225908L;
	
	public static interface FieldSpecs extends Serializable {
		int CODE_MAX = 10;
		int DESC_MAX = 300;
	}

	public static final String TABLE = "company_group";
	
	public static final String COL_COMPANY_ID = "company_id";
	public static final String COL_CODE = "code";
	public static final String COL_DESC = "description";

	@Id
	@Column(name = COL_CODE, nullable = false, unique = true, length = FieldSpecs.CODE_MAX)	
	private String code;
	
	@ManyToOne
	@JoinColumn(name = COL_COMPANY_ID, nullable = false)
	private Company company;
	
	@Column(name = COL_DESC, nullable = true, length = FieldSpecs.DESC_MAX)
	private String description;
	
	public CompanyGroup() {
		
	}
	
	public CompanyGroup(Company company, String code) {
		this.company = company;
		this.code = code;
	}
	
	@Override
	public boolean equals(Object object) {
		if (object instanceof CompanyGroup)
		{
			CompanyGroup o = (CompanyGroup) object;
			return code.equals(o.code);
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return code == null ? super.hashCode() : code.hashCode();
	}
	
	@Override
	public String toString() {
		return code;
	}

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}
	
	public String getCompanyCode() {
		return company.getCode();
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}
